package org.sample.algorithm.tree.rbtree;

public class Node<T> {

    protected static final boolean RED = false;
    protected static final boolean BLACK = true;

    protected int key;
    protected T value;
    protected Node<T> left;
    protected Node<T> right;
    protected Node<T> parent;
    protected boolean color = BLACK;

    public Node(int key, T value, Node<T> parent) {
        this.key = key;
        this.value = value;
        this.parent = parent;
    }

    public Node(int key, T value, Node<T> left, Node<T> right, Node<T> parent) {
        this.key = key;
        this.value = value;
        this.left = left;
        this.right = right;
        this.parent = parent;
    }

    public int getKey() {
        return key;
    }

    public void setKey(int key) {
        this.key = key;
    }

    public T getValue() {
        return value;
    }

    public T setValue(T value) {
        T result = this.value;
        this.value = value;
        return result;
    }

    @Override
    public String toString() {
        return (color == RED ? "Red" : "Black") + ":" + key;
    }
}